package 竞赛.NO_398;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 *
 * @author lanran
 * @date 2024/5/19 10:36
 **/
public class 特殊数组II_100308 {
    public static void main(String[] args) {
        Solution s = new Solution();
        for (boolean b : s.isArraySpecial(new int[]{7, 5, 1, 8, 1, 1}, new int[][]{{0, 3}, {0, 1}, {5, 5}})) {
            System.out.println(b);
        }
    }

    static class Solution {
        public boolean[] isArraySpecial(int[] nums, int[][] queries) {
            boolean[] ans = new boolean[queries.length];
            Map<Integer, Integer> cache = new HashMap<>();
            a:
            for (int i = 0; i < queries.length; i++) {
                int[] query = queries[i];
                ans[i] = true;
                if (query[1] - query[0] < 1) {
                    continue;
                }
                if (cache.getOrDefault(query[0], -1) >= query[1]) {
                    continue;
                }
                for (int j = query[0]; j < query[1]; j++) {
                    boolean n1 = nums[j] % 2 == 0;
                    boolean n2 = nums[j + 1] % 2 == 0;
                    if ((n1 && n2) || (!n1 && !n2)) {
                        ans[i] = false;
                        continue a;
                    }
                }
                cache.put(query[0], query[1]);
            }
            return ans;
        }
    }
}
